package com.r_z.service.impl;

import com.r_z.entity.OrderDetails;
import com.r_z.entity.SalesOrder;
import com.r_z.mapper.SalesOrderMapper;
import com.r_z.service.SalesOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author z
 * @version 1.0
 * @date 2023/5/29
 */
@Service
public class SalesOrderServiceImpl implements SalesOrderService {
    @Resource
    SalesOrderMapper salesOrderMapper;
  /**销售订单查询*/
    @Override
    public List<SalesOrder> salesOrderList(String salesOrderId, int page, int limit) {
        StringBuffer strWhere=new StringBuffer("");
        if (salesOrderId!=null){
            strWhere=strWhere.append(" where salesOrderId  like '%"+salesOrderId+"%'");
        }else {
            strWhere=strWhere.append(" where salesOrderId  like '%%'");
        }
        String s = strWhere.toString();
        page=(page-1)*limit;
        return salesOrderMapper.salesOrderList(s,page,limit);
    }
    @Override
    /**
     * 查询销售订单总数
     * @param salesOrderId
     * @return
     */
    public int count(String salesOrderId) {
        StringBuffer strWhere=new StringBuffer("");
        if (salesOrderId!=null){
            strWhere=strWhere.append("where salesOrderId  like '%"+salesOrderId+"%'");
        }else {
            strWhere=strWhere.append("where salesOrderId  like '%%'");
        }
        String s = strWhere.toString();
        return salesOrderMapper.count(s);
    }
   /**新增销售订单*/
    @Override
    public int insertSalesOrder(SalesOrder salesOrder) {
        return salesOrderMapper.insertSalesOrder(salesOrder);
    }
/**修改销售订单*/
    @Override
    public int updateSalesOrder(SalesOrder salesOrder) {
        return salesOrderMapper.updateSalesOrder(salesOrder);
    }
/**删除销售订单*/
    @Override
    public int deleteSalesOrder(String salesOrderId) {
        return salesOrderMapper.deleteSalesOrder(salesOrderId);
    }

    /**
     * 销售订单详情
     * @param salesOrderId
     * @return
     */
    @Override
    public List<OrderDetails> OrderDetails(String salesOrderId) {
        return salesOrderMapper.orderList(salesOrderId);
    }

}
